(function () {
    function TimerSort() {
        TimerSort.super(this);

        this.name      = "TimerSort";
        this.timeout   = null;
        this.visible   = false;
        this.angleDiff = null;
        this.startAng  = -90;
        this.endAng    = -90;

        this.y = 143;
    }
    Laya.class(TimerSort, "ui.Com.TimerSort", ui.Room.UI.TimerSortUI);

    var _proto = TimerSort.prototype;
    /**
     * @privite
     * 计算倒计时时间并更新界面
     */
    _proto.onCountDown = function () {
        var timeout   = this.timeout;

        timeout = timeout <= 0 ? 0 : timeout;

        this.time.changeText(timeout < 10 ? "0" + timeout : timeout);
        this.circle.graphics.clear();
        this.circle.graphics.drawPie(69, 68, 52, this.startAng, (this.endAng += this.angleDiff), "#3a240d");

        if(timeout === 0){
            this.stop();
        }

        timeout--;
        this.timeout = timeout;
    }

    /**
     * @public
     * 准备计时器开始倒计时
     * 
     * @param {Number} timeout 倒计时开始时间
     */
    _proto.start = function (timeout) {
        utils.log("====-------TimerSort.CountDown-------=====");
        utils.log("剩余时间：" + timeout);

        this.visible = true;
        this.timeout = timeout;
        this.angleDiff = 360 / timeout | 0;

        this.onCountDown();
        Laya.timer.loop(1000, this, this.onCountDown);
    }
    /**
     * @public
     * 准备计时器结束倒计时
     */
    _proto.stop = function () {
        utils.log("====-------TimerSort.Stop-------=====");
        utils.log("剩余时间：" + this.timeout);

        this.x       = 306.5;
        this.y       = 143;
        this.endAng  = -90;
        this.timeout = null;
        this.visible = false;

        Laya.timer.clear(this, this.onCountDown);
        //this.removeSelf();
    }
})();